//
//  WHMoneyTopView.m
//  SquirrelSeller
//
//  Created by 邓伟浩 on 2019/1/6.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHMoneyTopView.h"

@interface WHMoneyTopView ()

@property (nonatomic, strong) UIView *topBackView;
@property (nonatomic, strong) UIImageView *dianImageView;
@property (nonatomic, strong) UIImageView *tipsImageView;
@property (nonatomic, strong) UILabel *tipsLabel;
@property (nonatomic, strong) UILabel *moneyLabel;

@end

@implementation WHMoneyTopView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpTopView];
    }
    return self;
}

- (void)setUpTopView {
    [self addSubview:({
        _topBackView = [[UIView alloc] init];
        
        _topBackView;
    })];
    [_topBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
    }];
    
    [_topBackView addSubview:({
        _dianImageView = [[UIImageView alloc] init];
        _dianImageView.image = IMAGE_NAMED(@"mywallet_dian_img");
        _dianImageView.contentMode = UIViewContentModeScaleAspectFit;
        _dianImageView.userInteractionEnabled = YES;
        
        _dianImageView;
    })];
    
    [_dianImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kRealwidth(260));
        make.height.mas_equalTo(kRealwidth(180));
        make.centerX.mas_equalTo(_topBackView.mas_centerX);
        make.centerY.mas_equalTo(_topBackView.mas_centerY);
    }];
    
    [_dianImageView addSubview:({
        _tipsLabel = [[UILabel alloc] init];
        _tipsLabel.textColor = KWhiteColor;
        _tipsLabel.font = SYSTEMFONT(kRealwidth(16));
        _tipsLabel.textAlignment = NSTextAlignmentCenter;
        _tipsLabel.text = @"提现 (元)";
        _tipsLabel;
    })];
    
    [_tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_dianImageView.mas_centerX).offset(-kRealwidth(10));
        make.height.mas_equalTo(kRealwidth(16));
        make.top.mas_equalTo(_dianImageView.mas_top).offset(kRealwidth(90));
        
    }];
    
    [_dianImageView addSubview:({
        _tipsImageView = [[UIImageView alloc] init];
        _tipsImageView.image = IMAGE_NAMED(@"icon_tips_whiteRight");
        _tipsImageView.userInteractionEnabled = YES;
        _tipsImageView;
    })];
    
    [_tipsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_tipsLabel.mas_centerY);
        make.left.mas_equalTo(_tipsLabel.mas_right).offset(kRealwidth(10));
        make.width.mas_equalTo(kRealwidth(10));
        make.height.mas_equalTo(kRealwidth(18));
    }];
    
    [_dianImageView addSubview:({
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.textColor = KWhiteColor;
        _moneyLabel.font = SYSTEMFONT(kRealwidth(45));
        _moneyLabel.textAlignment = NSTextAlignmentCenter;
        _moneyLabel.adjustsFontSizeToFitWidth = YES;
        _moneyLabel.text = @"0.00";
        
        _moneyLabel;
    })];
    
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_dianImageView.mas_centerX);
        make.height.mas_equalTo(kRealwidth(45));
        make.top.mas_equalTo(_tipsLabel.mas_bottom).offset(kRealwidth(24));
        make.width.mas_equalTo(kRealwidth(240));
        
    }];
    
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(moneyTap)];
    [self addGestureRecognizer:tapGes];
}

- (void)moneyTap {
    if (self.balanceTap) {
        self.balanceTap();
    }
}

- (void)setBalanceMoney:(NSString *)balanceMoney {
    _balanceMoney = balanceMoney;
    
    _moneyLabel.text = balanceMoney;
}

@end
